
import Vue from 'vue'
import Router from 'vue-router'
import { Preview, Reportview } from 'platform-business-components'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {  
  path: '/preview',
    name: 'preview',
    component: Preview
  },
  {
  path: '/reportview',
  name: 'reportview',
  component: Reportview
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    name: 'home',
    component: () => import('@/views/_home/index'),
    meta: { title: '首页', icon: 'home' }
  },
    {
        path: '/salesContract',
        name: '销售合同',
        meta: {title:  '销售合同管理', icon: 'table', code: 'CONTRACT_0011' },
        component: () => import('@/views/zhaomeng/salesContract')
    },
    {
        path: '/partner',
        name: '合作单位',
        meta: {title:  '合作单位管理', icon: 'table', code: 'CONTRACT_002' },
        component: () => import('@/views/zhaomeng/partner')
    },
    {
        path: '/purchaseContract',
        name: '采购合同',
        meta: {title:  '采购合同管理', icon: 'table', code: 'CONTRACT_0012' },
        component: () => import('@/views/zhaomeng/purchaseContract')
    },
    {
        path: '/principalPart',
        name: '主体单位',
        meta: {title:  '主体单位管理', icon: 'table', code: 'CONTRACT_003' },
        component: () => import('@/views/zhaomeng/principalPart')
    },
    {
        path: '/area',
        name: '地区',
        meta: {title:  '地区管理', icon: 'table', code: 'CONTRACT_004' },
        component: () => import('@/views/zhaomeng/area')
    },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const menus = JSON.parse(localStorage.getItem('menus'));
console.log(menus)
if(menus!=null){
  menus.forEach((item) => {
    if(item.path!=null&&item.path!=''){
      constantRoutes.push({
        path: item.path,
        name: item.name,
        component: resolve => require([`@/views/${item.component}/index`], resolve)
      })
    }
  })
}
const router = constantRoutes
export default router
